package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "评论相关接口")
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("查看评论")
    @GetMapping
    public ResponseEntity getCommentList(@RequestParam String movementId,
                                         @RequestParam(defaultValue = "1") Long page,
                                         @RequestParam(defaultValue = "10", name = "pagesize") Long pageSize) {
        PageResult pageResult = commentService.getCommentList(movementId, page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    @ApiOperation("发布评论")
    @PostMapping
    public ResponseEntity publishComment(@RequestBody Map<String, String> params) {
        commentService.addComment(params);
        return ResponseEntity.ok(null);
    }

    @ApiOperation("评论点赞")
    @GetMapping("/{id}/like")
    public ResponseEntity commentLike(@PathVariable String id) {
        Integer likeCount = commentService.like(id);
        return ResponseEntity.ok(likeCount);
    }

    @ApiOperation("评论取消点赞")
    @GetMapping("/{id}/dislike")
    public ResponseEntity commentDislike(@PathVariable String id) {
        Integer likeCount = commentService.dislike(id);
        return ResponseEntity.ok(likeCount);
    }

}
